<template>
  <section>
    <div id="logStr" v-html="logStr"></div>
  </section>
</template>


<script>
  import dao from '../../common/dao'
  import util from '../../common/util'
  export default {
    components: {},
    data() {
      return {
        html: '',
        logStr: ''
      }
    },
    methods: {
      getLogByUri(){
        let uri = this.query.uri
        dao.getYarnLogByFullPath({uri}).then(res => {
          if (res.FX.err)return false
          let html = res.body.results || "";
          this.rprul(html)
          //this.logStr = html
        })
      },
      getTaskAttemptRunLog(){
        let nodeId = this.query.nodeId
        let containerId = this.query.containerId
        let user = this.query.user
        dao.getTaskAttemptRunLog({nodeId,containerId,user}).then(res=>{
          if (res.FX.err)return false
          let html = res.body.results || "";
          this.rprul(html)
        })
      },
      rprul(html){
        let re = /<a[^>]*href=['"]([^"]*)['"][^>]*>(.*?)<\/a>/g;
        let as = html.match(re) || [];
        let h = '';
        as.map(item => {
          let reg = /\/node\/con(([\s\S]*?))"/
          let ah = (item.match(reg) || [])[0].replace(/"/,"");
          //let ac = item.match(/<(a)[^>]*>([\s\S]*?)(?=<\/\1>)/gi).join('').split(/<a[^>]*>/)[1]
          let node = this.query.node||this.query.nodeId;
          let newH = `${encodeURI(`${window.location.pathname}#/page3362?node=${node||''}&uri=http://${node||''}${ah}`)}"`
          h += `<p>${item.replace(reg, newH)}</p>`
        })
        this.logStr = h
      },
      pageInit(){
        this.query = this.$store.state.route.query || {};
        if (this.query.uri) this.getLogByUri();
        else this.getTaskAttemptRunLog()
      }
    },
    mounted: function () {
      this.pageInit();
      /*dao.getTrackingLog( util.fetch("page336") ||{}).then(res => {
       if (res.FX.err) return
       let html = res.body.results||"";
       //let tagOfAs= html.match(/<a(([\s\S])*?)<\/a>/g);
       let parms = html.match(/"\/jobhistory\/logs(([\s\S]*?))"/g)||[];
       parms.map(item=>{
       let newH =  `"${encodeURI(`${window.location.pathname}#/page337?parm=${item}`)}"`
       html = html.replace(/"\/jobhistory\/logs(([\s\S]*?))"/,newH)
       })
       this.logStr = html
       })*/
    }
  }
</script>

<style scoped>

</style>